package com.yutian.example.demo.forum.service;

import com.yutian.example.demo.forum.dao.TopicDAO;
import com.yutian.example.demo.forum.dao.model.Topic;
import com.yutian.example.demo.service.forum.ITopicService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
// @Component
public class TopicServiceImpl implements ITopicService {

    @Autowired
    private TopicDAO topicDAO;

    @Override
    public Topic get(Long id) {
        return topicDAO.get(id);
    }

    @Override
    public Topic insert(String title, String msg) {
        Topic topic = new Topic();
        topic.setMsg(msg);
        topic.setTitle(title);
        long num = topicDAO.insert(topic);
        System.out.println("插入了" + num + "条数据");
        System.out.println("插入的数据的id，是自增生成的，id=" + topic.getId());
        return topic;
    }
}
